﻿/*
 * Copyright (C) 2011, EADS France
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * Author: Laurent WOUTERS
 */

using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Hime.Redist.Parsers;

namespace xowl.gmi.compiler.ast
{
    class ASTPatternVariable : ASTPattern
    {
        protected string parentRoute;
        protected string property;
        protected bool isOrdered;
        
        public string ParentRoute { get { return parentRoute; } }
        public string Property { get { return property; } }
        public bool IsOrdered { get { return isOrdered; } }

        public ASTPatternVariable(string symbol, string property, bool isOrdered)
            : base(symbol)
        {
            this.property = property;
            this.isOrdered = isOrdered;
        }

        public override List<ASTPattern> Split()
        {
            List<ASTPattern> result = new List<ASTPattern>();
            result.Add(this);
            result.Add(new ASTPattern(null));
            return result;
        }

        public override void BuildVariableNodesList(List<ASTPattern> result)
        {
            result.Add(this);
            foreach (ASTPattern child in children)
                child.BuildVariableNodesList(result);
        }

        public override bool NeedRoute() { return true; }
        public override void SetParentRoute(string route) { parentRoute = route; }

        public override MinimalAST GetMinimalInner() { return null; }

        public override bool Equals(object obj)
        {
            ASTPatternVariable tested = obj as ASTPatternVariable;
            if (tested == null)
                return false;
            if (this.parentRoute != tested.parentRoute)
                return false;
            return NodeEquals(tested);
        }
        public override int GetHashCode() { return base.GetHashCode(); }
    }
}
